package com.pd.modules.common.logging;

import java.util.Observer;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

import com.pd.modules.common.Settings;

public class LogSingleton {
	

	private static final LogSingleton instance = new LogSingleton();

	public static Logger LOGGER;
	private LogView mLogView;
	private LogHandler mLogHandler;
	private LogModel mLogModel;

	private LogSingleton()
	{
		setupLogging();
	}

	public static LogSingleton getInstance()
	{
		return instance;
	}

	public void log(Level _level, String _message)
	{
		LOGGER.log(_level, _message);
	}

	private void setupLogging()
	{

		LOGGER = Logger.getLogger(LogSingleton.class.getName());

		try
		{
			mLogModel = new LogModel();

			mLogHandler = new LogHandler(mLogModel,Settings.LOGS_FILE,true);
			mLogHandler.setFormatter(new SimpleFormatter());	

			LOGGER.addHandler(mLogHandler);

			mLogView = new LogView(mLogModel);
			mLogModel.addObserver((Observer) mLogView);
		} catch (Exception e)
		{
			e.printStackTrace();
		}

	}

	public void showLogView(boolean _value)
	{
		mLogView.setVisible(_value);
	}

}
